package com.itheima.rabbitmq.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;


public class Producer {

    static final String QUEUE_NAME= "hello fff";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();

        connectionFactory.setHost("192.168.80.130");

        connectionFactory.setPort(5672);

        connectionFactory.setVirtualHost("/itcast");

        connectionFactory.setUsername("itheima");

        connectionFactory.setPassword("itheima");

       Connection connection = connectionFactory.newConnection();


        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, true, false, false, null);

        String message = "长颈鹿";

        channel.basicPublish("","hello fff",null,message.getBytes());

        System.out.println("已发送：" + message);

        channel.close();
        connection.close();
    }
}
